home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / apps / 102 / examples / excopies.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-01-25  |  803 b   |  23 lines

  1. #include <stdio.h>   /* found in MWC p. 406 */
  2. #define BUFSIZE (20*512)
  3. char buf[BUFSIZE];
  4.  
  5. main(argc,argv) int argc; char *argv[];
  6. {
  7.        register int ifd,ofd;
  8.        register unsigned int n;
  9. if (argc != 3)                     fatal("Usage:copy source destination");
  10. if ((ifd = open(argv[1],0)) == -1)       fatal("Cannot open input  file");
  11. if ((ofd = creat(argv[2], 1)) == -1)     fatal("Cannot open output file");
  12. while ((n = read(ifd, buf, BUFSIZE)) != 0)                           {
  13.        if (n == -1)                      fatal(" Read Error ");
  14.        if (write(ofd, buf,n) != n)       fatal(" Write Error");      }
  15. if(close(ifd) == -1 || close(ofd) == -1) fatal(" Cannot Close ");
  16. exit(0);
  17. }
  18. fatal(s) char *s;
  19. {
  20.        fprintf(stderr, "copy: %s\n",s);
  21.        exit(1);
  22. }
  23.